//
//  topRight.m
//  ILiangCang
//
//  Created by ZX on 16-4-18.
//  Copyright (c) 2016年 CRQ. All rights reserved.
//

#import "topRight.h"
#import "rightCell.h"
#import "UIImageView+WebCache.h"
#import "httpEngine.h"
#import "infosModel.h"


#define WIDTH [UIScreen mainScreen].bounds.size.width
#define HEIGHT [UIScreen mainScreen].bounds.size.height
@interface topRight ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic,strong)NSMutableArray * dataArray;

@end

@implementation topRight

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    _dataArray = [[NSMutableArray alloc]initWithCapacity:0];
    [self addTableView];
   
}

-(void)addTableView
{
    UITableView * table = [[UITableView alloc]init];
    table.frame = CGRectMake(0, 0, WIDTH, HEIGHT-49-15-64);
    table.delegate = self;
    table.dataSource = self;

    
    [self.view addSubview:table];
    [table registerClass:[rightCell class] forCellReuseIdentifier:@"cell"];
    [httpEngine requestToGetMagazineRightCompletion:^(NSMutableArray *rightArray, NSError *error) {
        _dataArray = rightArray;
        [table reloadData];
    }];
    
    table.rowHeight = 75;
    
}

//-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
//{
//    return 1;
//}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    rightCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    infosModel * info = _dataArray[indexPath.row];
    [cell.header sd_setImageWithURL:info.thumb];
    cell.titleLabel.text = info.authorName;
    cell.noteLabel.text = info.note;
    
    return cell;
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
